package com.adtec.base.cloud.baseservice.rbac.system.controller;

import com.adtec.base.cloud.baseservice.rbac.system.service.GlobalLogService;
import com.adtec.base.cloud.persistence.system.model.GlobalLog;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@RestController
@RequestMapping("/sysgloballog")
@Tag(name = "sysgloballog", description = "全局日志")
public class GlobalLogController {
    @Resource
    private GlobalLogService globalLogService;

    @PostMapping("/query")
    @Operation(description = "全局日志：查询")
    @Parameters({
            @Parameter(name = "url", description = "请求url"),
            @Parameter(name = "username", description = "请求用户"),
            @Parameter(name = "address", description = "请求Ip地址"),
            @Parameter(name = "createStartTime", description = "创建时间(区间查询开始)"),
            @Parameter(name = "createEndTime", description = "创建时间(区间查询结束)"),
            @Parameter(name = "pageNum", description = "分页展示页数"),
            @Parameter(name = "pageSize", description = "分页每页页数"),
    })
    public IPage<GlobalLog> query(@RequestParam(name = "url", required = false) String url,
                                  @RequestParam(name = "username", required = false) String username,
                                  @RequestParam(name = "address", required = false) String address,
                                  @RequestParam(name = "createStartTime", required = false) Date createStartTime,
                                  @RequestParam(name = "createEndTime", required = false) Date createEndTime,
                                  @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                  @RequestParam(name = "pageSize", defaultValue = "20") Integer pageSize) {

        return globalLogService.queryLog(url, username, address,
                createStartTime, createEndTime,
                pageNum, pageSize);
    }

}
